<?php

/**
 * galeria actions.
 *
 * @package    Terapia Vital
 * @subpackage galeria
 * @author     Foxsis
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class galeriaActions extends sfActionsFoxsis
{
	/**
	 * Executes index action
	 *
	 * @param sfRequest $request A request object
	 */
	public function executeIndex(sfWebRequest $request)
	{
		$paginaAtual = $this->_setActualPage();
		$this->filter = $this->_getFilter();
		
		$listQuery = GaleriaTable::carregarGalerias($this->filter, 'id_galeria DESC');
		
		$this->getContext()->getConfiguration()->loadHelpers('Url');
		$this->pager_layout = new Foxsis_Pager_Layout(
			$pager = new Doctrine_Pager(
				$listQuery,
				$paginaAtual,
				NUM_LIST_ITENS
			),
			new Doctrine_Pager_Range_Sliding(array('chunk' => MAX_PAGER_LINKS)),
			url_for('@galeria')
		);
		
		$this->galerias = $this->pager_layout->execute();
	}
	
	public function executeShow(sfWebRequest $request)
	{
		try {
			$this->galeria = $this->getRoute()->getObject();
		} catch(Exception $e){
			$this->getUser()->setFlash(
				'alert',
				'Não foi possível carregar a galeria, por favor tente novamente.');
			$this->redirect('@galeria');
		}
	}
}
